# You may edit this makefile as long as you keep these original 
# target names defined.
MODE=debug
GNATMAKE=gnatmake -XMODE=${MODE} -XPROCESSORS=4
GNATCLEAN=gnatclean
GPRPATH=asf.gpr

distdir=ada-asf-@ASF_VERSION@

DIST_FILE=ada-asf-@ASF_VERSION@.tar.gz

MKDIR=mkdir
CP=cp

srcdir = .
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
top_builddir = .

awadir=${prefix}/share/ada/awa
includedir=${prefix}/share/ada/adainclude
projectdir=${prefix}/share/ada/adainclude
libdir=${prefix}/lib
alidir=${prefix}/share/ada/adainclude

# Build executables for all mains defined by the project.
build:
	$(GNATMAKE) -p -P "$(GPRPATH)"

# Build and run the unit tests
test:	build
	$(GNATMAKE) -p -Ptests
	bin/asf_harness -config test.properties

# Not intended for manual invocation.
# Invoked if automatic builds are enabled.
# Analyzes only on those sources that have changed.
# Does not build executables.
autobuild:
	$(GNATMAKE) -gnatc -c -k  -P "$(GPRPATH)"

# Clean the root project of all build products.
clean:	clean_test
	$(GNATCLEAN) -q -P "$(GPRPATH)"

# Clean the files produced by the unit tests
clean_test:
	rm -rf regtests/result/*
	$(GNATCLEAN) -q -Ptests

# Clean root project and all imported projects too.
clean_tree:
	$(GNATCLEAN) -P "$(GPRPATH)" -r

# Check *all* sources for errors, even those not changed.
# Does not build executables.
analyze:
	$(GNATMAKE) -f  -gnatc -c -k  -P "$(GPRPATH)"

# Clean, then build executables for all mains defined by the project.
rebuild: clean build


# Files to package in source distribution
DISTFILES=README LICENSE.txt NOTICE.txt CHANGES config.guess configure config.sub \
configure.in Makefile.in install-sh distrib test.properties ChangeLog \
asf.gpr.in asfunit.gpr.in tests.gpr.in samples.gpr.in config.gpr \
src asfunit samples regtests web \
bin obj lib

dist:
	-rm -rf $(distdir)
	mkdir $(distdir)
	-chmod 777 $(distdir)
	here=`cd $(top_builddir) && pwd`; \
	top_distdir=`cd $(distdir) && pwd`; \
	distdir=`cd $(distdir) && pwd`; \
	for file in $(DISTFILES); do \
	  d=$(srcdir); \
	  if test -d $$d/$$file; then \
	    cp -pr $$d/$$file $(distdir)/$$file; \
	  else \
	    test -f $(distdir)/$$file \
	    || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
	    || cp -p $$d/$$file $(distdir)/$$file || :; \
	  fi; \
	done
	-rm -f $(distdir)/bin/*
	-rm -f $(distdir)/obj/*
	-rm -f $(distdir)/obj/asf/*
	-rm -f $(distdir)/obj/asfunit/*
	-rm -f $(distdir)/lib/*
	-rm -f $(distdir)/lib/asf/*
	-rm -f $(distdir)/lib/asfunit/*
	-rm -f $(distdir)/regtests/result/*
	tar --exclude=.svn --exclude="*~" --exclude="*.o" --exclude="*.ali" \
	    --exclude="*.log" --exclude="*.a" \
	    -cvzf $(DIST_FILE) $(distdir)

install:
	$(MKDIR) -p ${includedir}/asf
	$(MKDIR) -p ${includedir}/asfunit
	$(MKDIR) -p ${projectdir}/
	${MKDIR} -p ${alidir}/asf
	${MKDIR} -p ${alidir}/asfunit
	${MKDIR} -p ${awadir}/web/js
	${CP} asfunit/*.ad[bs] ${includedir}/asfunit
	${CP} src/*.ad[bs] ${includedir}/asf
	${CP} src/aws/*.ad[bs] ${includedir}/asf
	${CP} distrib/asf.gpr ${projectdir}/asf.gpr
	${CP} distrib/asfunit.gpr ${projectdir}/asfunit.gpr
	${CP} lib/asf/*.ali ${alidir}/asf
	${CP} lib/asfunit/*.ali ${alidir}/asfunit
	${CP} lib/asf/libasf.a ${libdir}/
	${CP} lib/asfunit/libasfunit.a ${libdir}/
	${CP} web/js/* ${awadir}/web/js

uninstall:
	rm -rf ${includedir}/asf
	rm -rf ${includedir}/asfunit
	rm -f ${libdir}/libasf.a
	rm -f ${libdir}/libasfunit.a
	rm -f ${projectdir}/asf.gpr
	rm -f ${projectdir}/asfunit.gpr
	rm -rf ${awadir}/web
